<?php
namespace app\controller\model;

use app\BaseController;
use app\controller\model\apis;
use think\facade\Db;

class Supplier extends BaseController
{
	protected $develop=false;
	protected $model;
	protected $tables,$supplier,$class;
    public function __construct($supplierID=0){
	    $this->tables = new Tables();
	    $this->supplier = DB::name($this->tables->supplier)->where("id",$supplierID)->find();
	    if(!$this->supplier) return false;
		$this->class = $this->supplier['apiID'];
		$this->setModel();
    }

	/**获取油站数据
	 * @param $gas
	 * @return mixed
	 */
	public function getGas($gas=[]){
		//获取一个gas信息
		return $this->model->getGas($gas);
	}

	/**获取账户余额
	 * @return mixed
	 */
	public function account(){
		return $this->model->account();
	}

	/**获取多个油站信息
	 * @param $gasID
	 * @return mixed
	 */
	public function getGases($gasID){
		return $this->model->getGases($gasID);
	}

	/**退回订单
	 * @param $supplier_no
	 * @return bool
	 */
	public function returnOrder($supplier_no){
		if($this->model==null)return true;
		return $this->model->returnOrder($supplier_no);
	}

	/**获取单个订单信息
	 * @param $supplier_no
	 * @return bool
	 */
	public function getOrder($supplier_no){
		if($this->model==null)return true;
		return $this->model->getOrder($supplier_no);
	}

	/**获取油站列表
	 * @param $cint
	 * @return bool|void
	 */
	public function getGasList($cint=1){
		if($this->model==null)return true;
		$this->model->getGasList($cint);
	}

	/** 单个测试的
	 * @param $cint
	 * @return bool|void
	 */
	public function test($cint=1){
		if($this->model==null)return true;
		$this->model->test($cint);
	}

	/**取消订单
	 * @param $supplier_no
	 * @return bool
	 */
	public function cancelOrder($supplier_no){
		if($this->model==null)return true;
		return $this->model->cancelOrder($supplier_no);
	}

	/** 下订单
	 * @param $order
	 * @return bool
	 */
	public function mkOrder($order){
		if($this->model==null)return true;
		return $this->model->mkOrder($order);
	}

	/** 确认订单 支付订单
	 * @param $supplier_no
	 * @return bool|void
	 */
	public function confirmOrder($supplier_no){
		if($this->model==null)return true;
		$this->model->confirmOrder($supplier_no);
		//如果确认失败直接echojson
	}
	/**
	 * @return void
	 */
	//不能使用变量直接调用方法，会有任意执行漏洞
	protected function setModel(){
		if($this->class == 'panda')$this->model = new apis\ApiPanda($this->supplier);
		if($this->class == 'Hi')$this->model = new apis\Hi($this->supplier);
		if($this->class == 'tuanyou')$this->model = new apis\Tuanyou($this->supplier);
		if($this->model==null) echojson([],1,'缺少接口文件');
	}

}
?>